package src;

import java.util.ArrayList;
import java.util.Stack;

public class Solution1 {
    public boolean IsPopOrder(int [] pushA,int [] popA) {

        Stack<Integer>st=new Stack<>();
    // 入栈：当栈为空，或者栈顶元素和待出栈元素不相等时
        int pushAdex=0;
        int popdex=0;
        while(popdex<popA.length){
           while(st.empty()||st.peek()!=popA[popdex]){
               if(pushAdex<pushA.length){
                   st.push(pushA[pushAdex]);
                   pushAdex++;
               }else{
                   return false;
               }


           }
           //与带出元素相同
           st.pop();
           popdex++;
        }
        //pop全部弹出,出循环必是true
        return true;
    }
}